<?php
/**
 * Bean holding client information. 
 */
class RequestClient {
	private $strName;
	private $strIP;
	private $intPort;
	
	/**
	 * Collects information from $_SERVER variables.
	 */
	public function __construct() {		
		$this->setIp();
		// $this->setName();
		$this->setPort();
	}
	
	/**
	 * Sets client host name. Not done automatically, because gethostbyaddr makes application lag.
	 * 
	 * @return void
	 */
	private function setName() {
		$this->strName = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
	}
	
	/**
	 * Gets client host name.
	 * 
	 * @return string
	 */
	public function getName() {
		return $this->strName;
	}
	
	/**
	 * Sets client IP address.
	 * 
	 * @return void
	 */
	private function setIP() {
		$this->strIP = $_SERVER["REMOTE_ADDR"];
		
	}
	
	/**
	 * Gets client IP address
	 * 
	 * @return string
	 */
	public function getIP() {
		return $this->strIP;
	}
	
	/**
	 * Sets client port
	 * 
	 * @return void
	 */
	private function setPort() {
		$this->intPort = $_SERVER["REMOTE_PORT"];		
	}
	
	/**
	 * Gets client port
	 * 
	 * @return int
	 */
	public function getPort() {
		return $this->intPort;
	}
	
	/**
	 * Outputs collected information as associative array.
	 * 
	 * @return array
	 */
	public function toArray() {
		$tblOutput = array();
		$tblOutput['name'] = $this->strName;
		$tblOutput['ip'] = $this->strIP;
		$tblOutput['port'] = $this->intPort;
		return $tblOutput;
	}
}